<template>
  <a-spin :spinning="confirmLoading" style="background: #fff">
    <j-form-container :disabled="false">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-collapse v-model="activeKey">
          <a-collapse-panel key="1" header="供方信息">
            <a-row :gutter="48">
              <a-col :span="8">
                <a-form-model-item label="供应商名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="supplyCompanName">
                  <div style="position: relative;">
                    <SelectSupplierInput :disabled="checkDisabled('supplyCompanName')" placeholder="请选择供应商名称" v-model="model.supplyCompanName" @back="supplyCompanBack" :isProPayContract="true"/>
                    <div style="position: absolute;right: -30px;top: 0;cursor: pointer;" v-if="!checkDisabled('supplyCompanName')">
                      <a-icon type="plus" style="color:#1890FF" @click="$refs.unSupplier.getInitData()"/>
                    </div>
                  </div>
                  
                </a-form-model-item>
              </a-col>
              <a-col :span="8">
                <a-form-model-item label="公司地址" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="supplyCompanyAddress">
                  <a-input v-model="model.supplyCompanyAddress" :disabled="checkDisabled('supplyCompanyAddress')" placeholder="请输入公司地址"/>
                </a-form-model-item>
              </a-col>
              <a-col :span="8">
                <a-form-model-item label="委托代理人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="supplyEntrustedAgent">
                  <a-input :disabled="checkDisabled('supplyEntrustedAgent')" v-model="model.supplyEntrustedAgent" placeholder="请输入委托代理人" ></a-input>
                </a-form-model-item>
              </a-col>
              <a-col :span="8">
                <a-form-model-item label="手机号码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="supplyPhoneNumber">
                  <a-input :disabled="checkDisabled('supplyPhoneNumber')" v-model="model.supplyPhoneNumber" placeholder="请输入手机号码" ></a-input>
                </a-form-model-item>
              </a-col>
              <a-col :span="8">
                <a-form-model-item label="开户银行" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="supplyBankName">
                  <a-input :max-length="32" v-model="model.supplyBankName" placeholder="请输入开户银行" disabled></a-input>
                </a-form-model-item>
              </a-col>
              <a-col :span="8">
                <a-form-model-item label="银行账号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="supplyBankAccountNo">
                  <a-input v-model="model.supplyBankAccountNo" placeholder="请输入银行账号" disabled></a-input>
                </a-form-model-item>
              </a-col>
              <a-col :span="24">
                <a-form-model-item label="纳税人识别号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="supplyRegistrationNumber">
                  <a-input v-model="model.supplyRegistrationNumber" placeholder="请输入纳税人识别号" disabled></a-input>
                </a-form-model-item>
              </a-col>
            </a-row>
          </a-collapse-panel>
          <a-collapse-panel key="2" header="基本信息">
            <a-row :gutter="48">
              <a-col :span="8" :hidden="true">
                <a-form-model-item label="标题" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="bpmBizTitle">
                  <a-input :disabled="checkDisabled('bpmBizTitle')" v-model="model.bpmBizTitle" placeholder="请输入标题" ></a-input>
                </a-form-model-item>
              </a-col>
              <a-col :span="8">
                <a-form-model-item label="单据编号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="purchaseBill">
                  <a-input v-model="model.purchaseBill" placeholder="请输入单据编号" disabled></a-input>
                </a-form-model-item>
              </a-col>
              <a-col :span="8">
                <a-form-model-item label="申请人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="proposer">
                  <select-user-by-dep
                    placeholder="请选择申请人"
                    v-model="model.proposer"
                    disabled/>
                </a-form-model-item>
              </a-col>
              <a-col :span="8">
                <a-form-model-item label="申请时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="createTime">
                  <j-date
                    placeholder="请选择申请时间"
                    v-model="model.createTime"
                    :show-time="true"
                    date-format="YYYY-MM-DD HH:mm"
                    style="width: 100%"
                    disabled/>
                </a-form-model-item>
              </a-col>
              <a-col :span="8">
                <a-form-model-item label="申请部门" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="proposerDeptId">
                  <j-select-depart placeholder="请选择申请部门" v-model="model.proposerDeptId" disabled/>
                </a-form-model-item>
              </a-col>
              <a-col :span="8">
                <a-form-model-item label="申请人所属团队" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="applyTeam">
                  <select-team-input
                    :disabled="checkDisabled('applyTeam')"
                    v-model="model.applyTeam"
                    :tdlx="1"/>
                </a-form-model-item>
              </a-col>
              <a-col :span="8">
                <a-form-model-item label="合同名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="contractName">
                  <a-input :disabled="checkDisabled('contractName')" v-model="model.contractName" placeholder="请输入合同名称" ></a-input>
                </a-form-model-item>
              </a-col>
              <a-col :span="8">
                <a-form-model-item label="采购类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="procurementType">
                  <j-dict-select-tag @input="handleChangeProvisionType" :disabled="checkDisabled('procurementType')" type="list" v-model="model.procurementType" dictCode="procurement_type" placeholder="请选择采购类型"/>
                </a-form-model-item>
              </a-col>
              <a-col :span="8" v-if = "model.procurementType === '1'" >
                <a-form-model-item label="关联单据" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="associationBillId">
                  <a-input v-if="checkDisabled('associationBillId')" readOnly @click.prevent="goPurchaseCalibrationDetail(model)"  v-model="model.calibrationNo" style="color: #1890FF; cursor: pointer;"  placeholder="请关联定标结果确认单"></a-input>
                  <select-purchase-calibration-input v-else billStatus="1,2" :disabled="checkDisabled('associationBillId')" placeholder="请关联定标结果确认单" v-model="model.associationBillId" allowExistAll="yes"  />
                </a-form-model-item>
              </a-col>
              <a-col :span="8" v-if = "model.procurementType === '2'" >
                <a-form-model-item label="关联单据" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="associationBillId">
                  <a-input v-if="checkDisabled('associationBillId')" readOnly @click.prevent="goPurchaseApplyDetail(model)"  v-model="model.purchaseNo" style="color: #1890FF; cursor: pointer;"  placeholder="请关联采购申请单"></a-input>
                  <select-purchase-apply-form-contract-input v-else :disabled="checkDisabled('associationBillId')" placeholder="请关联采购申请单" v-model="model.associationBillId"  />
                </a-form-model-item>
              </a-col>
              <a-col :span="8" v-if = "model.procurementType === '3'" >
                <a-form-model-item label="关联单据" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="associationBillId">
                  <a-input v-if="checkDisabled('associationBillId')" readOnly @click.prevent="goInvitationDetail(model)"  v-model="model.invitationNo" style="color: #1890FF; cursor: pointer;"  placeholder="请关联采购申请单"></a-input>
                  <SelectPurchasingRequisitionInput v-else  v-model="model.associationBillId" placeholder="请关联招标采购申请单"  :disabled="checkDisabled('associationBillId')" />
                </a-form-model-item>
              </a-col>
<!--              <a-col :span="8">-->
<!--                <a-form-model-item label="关联单据" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="procurementType">-->
<!--                  <select-purchase-calibration-input  :disabled="checkDisabled('procurementType')" placeholder="请关联定标结果确认单" allowExistAll="yes" v-model="model.calibrationId" :projectId="model.xmmc"  />-->
<!--                  <select-purchase-apply-form-contract-input  :disabled="checkDisabled('procurementType')" placeholder="请关联采购申请单" v-model="model.purchaseApplyId"  />-->
<!--                </a-form-model-item>-->
<!--              </a-col>-->


              <a-col :span="8">
                <a-form-model-item label="签订日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="signingDate">
                  <j-date
                    placeholder="请选择申请时间"
                    :disabled="checkDisabled('signingDate')"
                    v-model="model.signingDate"
                    :show-time="true"
                    date-format="YYYY-MM-DD HH:mm"
                    style="width: 100%"/>
                </a-form-model-item>
              </a-col>
              <a-col :span="8">
                <a-form-model-item label="定点合同" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="isFixedTime">
                  <j-dict-select-tag
                  :disabled="checkDisabled('isFixedTime')"
                  type="radio"
                  v-model="model.isFixedTime"
                  dictCode="YES_OR_NO"
                  placeholder="请选择定点合同"
                  @input="isFixedTimeInput"
                />
                </a-form-model-item>
              </a-col>
              <a-col :span="8" v-if="model.isFixedTime == 1">
                <a-form-model-item label="到期日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="expireTime">
                  <j-date
                    placeholder="请选择到期日期"
                    :disabled="checkDisabled('expireTime')"
                    v-model="model.expireTime"
                    :show-time="true"
                    date-format="YYYY-MM-DD HH:mm:ss"
                    style="width: 100%"/>
                </a-form-model-item>
              </a-col>
              <a-col :span="8">
                <a-form-model-item label="合同总额(元)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="totalAmount">
                  <a-input-number
                    :max="99999999"
                    :min="0"
                    :precision="2"
                    v-model="model.totalAmount"
                    placeholder="请输入合同总额"
                    disabled
                    style="width: 100%" />
                </a-form-model-item>
              </a-col>
              <a-col :span="8">
                <a-form-model-item label="发票类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="invoiceCategory">
                  <j-dict-select-tag :disabled="checkDisabled('invoiceCategory')" type="list" v-model="model.invoiceCategory" dictCode="invoice_type" placeholder="请选择发票类型" @blur="invoiceCategoryBlur"/>
                </a-form-model-item>
              </a-col>
              <a-col :span="8">
                <a-form-model-item label="税率(%)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="taxRate">
                  <a-input
                    style="width: 100%"
                    type="number"
                    :disabled="checkDisabled('taxRate')"
                    addon-after="%"
                    placeholder="请输入税率"
                    @blur="inputTaxRateBlur"
                    v-model="model.taxRate" />
                </a-form-model-item>
              </a-col>
              <a-col :span="8">
                <a-form-model-item label="税费(元)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="expensesTaxation"> <!--  计算出来 -->
                  <a-input-number
                    disabled
                    :max="99999999"
                    :min="0"
                    v-model="model.expensesTaxation"
                    placeholder="请输入税费"
                    style="width: 100%" />
                </a-form-model-item>
              </a-col>
<!--              迭代16.8：字段货期、运输方式、运输费承担方删除；-->
<!--              <a-col :span="8">-->
<!--                <a-form-model-item label="货期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="deliveryTime">-->
<!--                  <a-input v-model="model.deliveryTime" :disabled="checkDisabled('deliveryTime')" style="width: 100%" placeholder="请输入货期">-->
<!--                    <j-dict-select-tag-->
<!--                      :style="model.deliveryTimeUnit?'width: 70px;':'width: 142px;'"-->
<!--                      slot="addonAfter"-->
<!--                      :disabled="checkDisabled('deliveryTime')"-->
<!--                      type="list"-->
<!--                      v-model="model.deliveryTimeUnit"-->
<!--                      placeholder="请选择货期单位"-->
<!--                      dictCode="period_validity_unit"/>-->
<!--                  </a-input>-->
<!--                </a-form-model-item>-->
<!--              </a-col>-->
<!--              <a-col :span="8">-->
<!--                <a-form-model-item label="运输方式" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="modeTransportation">-->
<!--                  <j-dict-select-tag :disabled="checkDisabled('modeTransportation')" type="list" v-model="model.modeTransportation" dictCode="transportation_type" placeholder="请选择运输方式" />-->
<!--                </a-form-model-item>-->
<!--              </a-col>-->
<!--              <a-col :span="8">-->
<!--                <a-form-model-item label="运输费承担方" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="trafficExpense">-->
<!--                  <j-dict-select-tag :disabled="checkDisabled('trafficExpense')" type="list" v-model="model.trafficExpense" dictCode="transportation_bearer" placeholder="请选择运输费承担方" />-->
<!--                </a-form-model-item>-->
<!--              </a-col>-->
<!--              迭代16.8：字段“关联团队”改为“费用所属团队”-->
              <a-col :span="8">
                <a-form-model-item label="费用所属团队" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="teamId">
                  <select-team-input placeholder="请选择团队" :disabled="checkDisabled('teamId')" v-model="model.teamId" :tdlx="3" @back="teamBack"/>
                </a-form-model-item>
              </a-col>
              <a-col :span="8">
                <a-form-model-item label="是否工程类" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="isEngineering">
                  <j-dict-select-tag :disabled="checkDisabled('isEngineering')" type="radio" v-model="model.isEngineering" dictCode="YES_OR_NO" placeholder="请选择是否工程类" />
                </a-form-model-item>
              </a-col>

              <!-- 暂时隐藏 -->
              <!-- <a-col :span="8" v-if="model.isProject == 1">
                <a-form-model-item label="是否关联项目" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="isProject">
                  <j-dict-select-tag :disabled="checkDisabled('isProject')" type="radio" v-model="model.isProject" dictCode="YES_OR_NO" placeholder="请选择是否关联项目" @blur="isProjectBlur"/>
                </a-form-model-item>
              </a-col>
              <a-col :span="8" v-if="model.isProject == 1">
                <a-form-model-item label="关联项目" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="projectId">
                  <select-project-input v-model="model.projectId" placeholder="请选择关联项目" :disabled="checkDisabled('projectId') || !model.teamId" :teamId="model.teamId" @input="selectProject" />
                </a-form-model-item>
              </a-col> -->
            <!-- </a-row> -->
            <!--              迭代16.8加入字段是否用印、印章类型、用印份数-->
            <!-- <a-row :gutter="48"> -->
              <a-col :span="8">
                <a-form-model-item label="是否用印" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="isUseSeal">
                  <j-dict-select-tag
                    :disabled="checkDisabled('isUseSeal')"
                    type="radio"
                    v-model="model.isUseSeal"
                    dictCode="yn"
                    @input="handleChangeSeal"
                    placeholder="请选择是否用印"/>
                </a-form-model-item>
              </a-col>
              <template v-if="isShowSeal">
                <a-col :span="8" >
                  <a-form-model-item label="用印类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="signSealWay">
                    <j-dict-select-tag
                      :disabled="checkDisabled('signSealWay')"
                      type="select"
                      v-model="model.signSealWay"
                      dictCode="seal_way"
                      @input="handleSignSealWay"
                      placeholder="请选择用印类型"/>
                  </a-form-model-item>
                </a-col>
                <template v-if="model.isUseSeal == '1' && model.signSealWay == 'online'">
                  <a-col :span="8">
                    <a-form-model-item label="对方是否电子签章" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="isSignSeal">
                      <j-dict-select-tag
                        :disabled="checkDisabled('isSignSeal')"
                        type="radio"
                        v-model="model.isSignSeal"
                        @input="isSignSealInput"
                        dictCode="yes_no"
                        placeholder="请选择对方是否电子签章"/>
                    </a-form-model-item>
                  </a-col>
                  <a-col :span="8" v-if="model.isSignSeal && model.isSignSeal == 1">
                    <a-form-model-item label="对方盖章人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="supplyPsnName">
                      <a-input :disabled="checkDisabled('supplyPsnName')" v-model="model.supplyPsnName" placeholder="请输入对方盖章人"></a-input>
                    </a-form-model-item>
                  </a-col>
                  <a-col :span="8" v-if="model.isSignSeal && model.isSignSeal == 1">
                    <a-form-model-item label="联系方式" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="supplyPsnMobile">
                      <a-input :disabled="checkDisabled('supplyPsnMobile')" v-model="model.supplyPsnMobile" placeholder="请输入联系方式"></a-input>
                    </a-form-model-item>
                  </a-col>
                </template>

                <a-col :span="8">
                  <a-form-model-item label="印章类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sealType">
                    <j-multi-select-tag
                      :disabled="checkDisabled('sealType')"
                      type="select"
                      v-model="model.sealType"
                      dictCode="yzlx_type"
                      placeholder="请选择印章类型"/>
                  </a-form-model-item>
                </a-col>
                <a-col :span="8">
                  <a-form-model-item label="用印份数" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="useSealNumber">
                    <a-input-number
                      :disabled="checkDisabled('useSealNumber')"
                      :max="99999999"
                      :min="0"
                      v-model="model.useSealNumber"
                      placeholder="请输入用印份数"
                      style="width: 100%"/>
                  </a-form-model-item>
                </a-col>
              </template>
            </a-row>
          </a-collapse-panel>
          <a-collapse-panel key="3" header="需方信息">
            <a-row :gutter="48">
              <a-col :span="8">
                <a-form-model-item label="公司名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="demandCompanName">
                  <select-Company-input :disabled="checkDisabled('demandCompanName')" v-model="model.demandCompanName" @back="demandCompanNameInput"/>
                </a-form-model-item>
              </a-col>

              <template v-if="model.isUseSeal == '1' && model.signSealWay == 'online'">
                <a-col :span="8">
                  <a-form-model-item label="我方经办人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="psnName">
                    <a-input :disabled="checkDisabled('psnName')" v-model="model.psnName" placeholder="请输入我方经办人"></a-input>
                  </a-form-model-item>
                </a-col>
                <a-col :span="8">
                  <a-form-model-item label="联系方式" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="psnMobile">
                    <a-input :disabled="checkDisabled('psnMobile')" v-model="model.psnMobile" placeholder="请输入联系方式"></a-input>
                  </a-form-model-item>
                </a-col>
              </template>
<!--              迭代16.8： 删除字段公司地址、委托代理人、手机号码、开户银行、银行账号、纳税人识别号。-->
<!--              <a-col :span="8">-->
<!--                <a-form-model-item label="公司地址" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="demandCompanyAddress">-->
<!--                  <a-input :disabled="checkDisabled('demandCompanyAddress')" v-model="model.demandCompanyAddress" placeholder="请输入公司地址" disabled></a-input>-->
<!--                </a-form-model-item>-->
<!--              </a-col>-->
<!--              <a-col :span="8">-->
<!--                <a-form-model-item label="委托代理人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="demandEntrustedAgent">-->
<!--                  <a-input :disabled="checkDisabled('demandEntrustedAgent')" v-model="model.demandEntrustedAgent" placeholder="请输入委托代理人" ></a-input>-->
<!--                </a-form-model-item>-->
<!--              </a-col>-->
<!--              <a-col :span="8">-->
<!--                <a-form-model-item label="手机号码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="demandPhoneNumber">-->
<!--                  <a-input :disabled="checkDisabled('demandPhoneNumber')" v-model="model.demandPhoneNumber" placeholder="请输入手机号码" ></a-input>-->
<!--                </a-form-model-item>-->
<!--              </a-col>-->
<!--              <a-col :span="8">-->
<!--                <a-form-model-item label="开户银行" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="demandBankName">-->
<!--                  <a-input :disabled="checkDisabled('demandBankName')" v-model="model.demandBankName" placeholder="请输入开户银行" disabled></a-input>-->
<!--                </a-form-model-item>-->
<!--              </a-col>-->
<!--              <a-col :span="8">-->
<!--                <a-form-model-item label="银行账号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="demandBankAccountNo">-->
<!--                  <a-input :disabled="checkDisabled('demandBankAccountNo')" :max-length="32" v-model="model.demandBankAccountNo" placeholder="请输入银行账号" disabled/>-->
<!--                </a-form-model-item>-->
<!--              </a-col>-->
<!--              <a-col :span="24">-->
<!--                <a-form-model-item label="纳税人识别号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="demandRegistrationNumber">-->
<!--                  <a-input :disabled="checkDisabled('demandRegistrationNumber')" v-model="model.demandRegistrationNumber" placeholder="请输入纳税人识别号" disabled></a-input>-->
<!--                </a-form-model-item>-->
<!--              </a-col>-->
            </a-row>
          </a-collapse-panel>

<!--          迭代16.8： 交接信息：字段全部删除
-->
<!--          <a-collapse-panel key="4" header="交接信息">-->
<!--            <a-row :gutter="48">-->
<!--              <a-col :span="8">-->
<!--                <a-form-model-item label="交货地址" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="deliveryAddress">-->
<!--                  <a-input :disabled="checkDisabled('deliveryAddress')" v-model="model.deliveryAddress" placeholder="请输入交货地址" ></a-input>-->
<!--                </a-form-model-item>-->
<!--              </a-col>-->
<!--              <a-col :span="8">-->
<!--                <a-form-model-item label="收货人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="consignee">-->
<!--                  <a-input :disabled="checkDisabled('consignee')" v-model="model.consignee" placeholder="请输入收货人" ></a-input>-->
<!--                </a-form-model-item>-->
<!--              </a-col>-->
<!--              <a-col :span="8">-->
<!--                <a-form-model-item label="收货人电话" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="phoneNumber">-->
<!--                  <a-input :disabled="checkDisabled('phoneNumber')" v-model="model.phoneNumber" placeholder="请输入收货人电话" ></a-input>-->
<!--                </a-form-model-item>-->
<!--              </a-col>-->
<!--              <a-col :span="8">-->
<!--                <a-form-model-item label="发票邮寄地址" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="invoiceAddress">-->
<!--                  <a-input :disabled="checkDisabled('invoiceAddress')" v-model="model.invoiceAddress" placeholder="请输入发票邮寄地址" ></a-input>-->
<!--                </a-form-model-item>-->
<!--              </a-col>-->
<!--              <a-col :span="8">-->
<!--                <a-form-model-item label="发票收件人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="invoiceConsignee">-->
<!--                  <a-input :disabled="checkDisabled('invoiceConsignee')" v-model="model.invoiceConsignee" placeholder="请输入发票收件人" ></a-input>-->
<!--                </a-form-model-item>-->
<!--              </a-col>-->
<!--              <a-col :span="8">-->
<!--                <a-form-model-item label="发票收货人电话" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="invoiceNumber">-->
<!--                  <a-input :disabled="checkDisabled('invoiceNumber')" v-model="model.invoiceNumber" placeholder="请输入发票收货人电话" ></a-input>-->
<!--                </a-form-model-item>-->
<!--              </a-col>-->
<!--            </a-row>-->
<!--          </a-collapse-panel>-->
          <a-collapse-panel key="5" header="其他信息">
            <a-row :gutter="48">
<!--              其他信息：（删除）删除验收条款-->
<!--              <a-col :span="24">-->
<!--                <a-form-model-item label="验收条款" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="inspectionClaus">-->
<!--                  <a-textarea :disabled="checkDisabled('inspectionClaus')" :max-length="500" v-model="model.inspectionClaus" rows="4" placeholder="请输入验收条款"/>-->
<!--                </a-form-model-item>-->
<!--              </a-col>-->
              <a-col :span="24">
                <a-form-model-item label="备注" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="remark">
                  <a-textarea :disabled="checkDisabled('remark')" :max-length="500" v-model="model.remark" rows="4" placeholder="请输入备注"/>
                </a-form-model-item>
              </a-col>
            </a-row>
          </a-collapse-panel>

          <a-collapse-panel key="6" header="付款信息">
            <ErpPurchaseContractPaymentList ref="contractPayment" @onTotalMoney="onTotalMoney" :disabled="checkDisabled('')"></ErpPurchaseContractPaymentList>
          </a-collapse-panel>
          <a-collapse-panel key="7" header="物料信息">
            <ErpPurchaseContractSuppliesList ref="contractSupplies" :disabled="checkDisabled('')"></ErpPurchaseContractSuppliesList>
          </a-collapse-panel>
          

          <a-collapse-panel key="9" header="合同原件扫描件">
            <a-row :gutter="48">
              <a-col :span="24">
                <a-form-model-item label="合同原件扫描件(仅合同管理员上传)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="contractOrgFile">
                  <j-upload v-if="!checkDisabled('contractOrgFile') && formBpm" :disabled="checkDisabled('contractOrgFile')" v-model="model.contractOrgFile" fileFormat=".pdf, .PDF"
                    fileType="file"></j-upload>
                  <a-button v-else icon="download" @click="viewFile(model.contractOrgFile)">文件列表</a-button>
                </a-form-model-item>
              </a-col>
            </a-row>
          </a-collapse-panel>
          <a-collapse-panel key="10" header="附件信息">
            <a-row :gutter="48">
              <a-col :span="24" v-if="model.isUseSeal == 1">
                <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="signFile">
                  <template v-slot:label>
                    <span >用印文件</span><span style="color: #faad14;font-weight: 600">（请上传只需盖章的用印文件！）</span>
                  </template>
                  <j-upload
                    v-if="!checkDisabled('signFile')"
                    :disabled="checkDisabled('signFile')"
                    v-model="model.signFile"
                    :multiple="false"
                    fileFormat=".pdf, .PDF, .doc, .docx"
                    fileFormatText="请上传word与pdf格式的文件！"
                    fileType="file"
                    :fillSize="50"
                    :isSingle="true"
                  ></j-upload>
                  <a-button v-else icon="download" @click="viewFile(model.signFile)">文件列表</a-button>
                </a-form-model-item>
              </a-col>
              <a-col :span="24">
                <a-form-model-item prop="purchaseFile" label="相关附件">
                  <j-upload v-if="!checkDisabled('purchaseFile')" :disabled="checkDisabled('purchaseFile')" v-model="model.purchaseFile"></j-upload>
                  <a-button v-else icon="download" @click="viewFile(model.purchaseFile)">文件列表</a-button>
                </a-form-model-item>
              </a-col>
            </a-row>
          </a-collapse-panel>
          <!-- <a-row :gutter="48">
            <a-col v-if="showFlowSubmitButton" :span="24" style="text-align: center">
              <a-button @click="submitForm">提 交</a-button>
            </a-col>
          </a-row> -->
        </a-collapse>
      </a-form-model>
      <common-flow-list v-if="formBpm && model.bpmStatus !== '1'" :formData="formData" style="margin-top: 10px"></common-flow-list>
      <view-file-modal ref="viewFileModal"></view-file-modal>
    </j-form-container>
    <a-row :gutter="48">
      <a-col :span="24" style="text-align: center;margin-top: 15px">
        <a-button type="primary" v-if="formBpm" :style="{ marginRight: showFlowSubmitButton?'10px':'0px' }" @click="onPrint">打印</a-button>
        <a-button @click="submitForm('submit')" v-if="showFlowSubmitButton">提 交</a-button>
      </a-col>
    </a-row>
    <ErpPurchaseContractFormPrint id="contractContent" v-if="formBpm" class="print_style" :formData="model" :formDataHistory="formData"></ErpPurchaseContractFormPrint>
    <ErpPurchaseCalibrationBillPenetrate ref="purchaseCalibrationBillPenetrate" ></ErpPurchaseCalibrationBillPenetrate>

    <ErpPurchaseApplyFormPenetrate ref="purchaseApplyFormPenetrate" ></ErpPurchaseApplyFormPenetrate>
    <ErpPurchaseApplyInvitationPenetrate ref="purchaseInvitationFormPenetrate" ></ErpPurchaseApplyInvitationPenetrate>
    <unSupplierForm ref="unSupplier" />
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { viewFile } from '@/utils/util'
  import { mapGetters } from 'vuex'
  import moment from 'moment'
  import SelectUserByDep from '@/views/scy/components/SelectUserByDep'
  import ViewFileModal from '@/views/scy/components/ViewFileModal'
  import SelectTeamInput from '@/views/scy/components/SelectTeamInput'
  import SelectProjectInput from '@/views/scy/components/SelectProjectInput'
  import SelectSupplierInput from '@/views/scy/components/selectSupplier/SelectSupplierInput.vue'
  import SelectPurchaseCalibrationInput from '@/views/scy/components/SelectPurchaseCalibrationInput'
  import SelectPurchaseApplyFormContractInput from '@/views/scy/components/SelectPurchaseApplyFormContractInput'
  import SelectPurchasingRequisitionInput from '@/views/scy/components/SelectPurchasingRequisitionInput'
  import ErpPurchaseContractSuppliesList from './reference/ErpPurchaseContractSuppliesList' // 物料信息管理列表
  import ErpPurchaseContractPaymentList from './reference/ErpPurchaseContractPaymentList' // 付款信息管理列表
  import SelectCompanyInput from '@/views/scy/components/SelectCompanyInput'
  import CommonFlowList from '@/views/components/CommonFlowList.vue';
  import Print from '@/utils/print/printarea.js';
  import ErpPurchaseContractFormPrint from './ErpPurchaseContractFormPrint' // 打印
  import ErpPurchaseCalibrationBillPenetrate from '@/views/scy/penetrate/ErpPurchaseCalibrationBillPenetrate'
  import ErpPurchaseApplyFormPenetrate from '@/views/scy/penetrate/ErpPurchaseApplyFormPenetrate'
  import ErpPurchaseApplyInvitationPenetrate from '@/views/scy/penetrate/ErpPurchaseApplyInvitationPenetrate'
  import unSupplierForm from '@/views/erp/purchase/supplier/comp/unSupplierForm.vue'

  import {Decimal} from 'decimal.js'
  export default {
    name: 'ErpPurchaseContractForm',
    components: {
      unSupplierForm,
      SelectUserByDep,
      ViewFileModal,
      SelectTeamInput,
      SelectProjectInput,
      SelectSupplierInput,
      ErpPurchaseContractSuppliesList,
      ErpPurchaseContractPaymentList,
      SelectCompanyInput,
      CommonFlowList,
      ErpPurchaseContractFormPrint,
      SelectPurchaseCalibrationInput,
      SelectPurchaseApplyFormContractInput,
      SelectPurchasingRequisitionInput,
      ErpPurchaseCalibrationBillPenetrate,
      ErpPurchaseApplyFormPenetrate,
      ErpPurchaseApplyInvitationPenetrate
    },
    mixins: [viewFile],
    props: {
      // 流程表单data
      formData: {
        type: Object,
        default: () => {},
        required: false
      },
      // 表单模式：true流程表单 false普通表单
      formBpm: {
        type: Boolean,
        default: false,
        required: false
      },
      // 表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        activeKey: ['1', '2', '3', '4', '5', '6', '7', '9', '10'],
        model: {
          purchaseBill: null,
          demandCompanName: '',
          isProject: 0,
          checkStatus: 0,
          allStorage: 0,
        },
        labelCol: {
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 24 }
        },
        confirmLoading: false,
        validatorRules: {
          signingDate: [
              { required: true, message: '请选择签订日期!', trigger: 'change' }
          ],
          applyTeam: [
            { required: true, message: '请选择申请人所属团队!' }
          ],
          signSealWay: [
            { required: true, message: '请选择用印类型!' }
          ],
          isSignSeal: [ { required: true, message: '请选择对方是否电子签章!' } ],
          supplyPsnName: [ { required: true, message: '请输入对方盖章人!' } ],
          supplyPsnMobile: [
            { required: true, message: '请输入联系方式!' },
            { pattern: /(^1\d{10}$|^(0\d{2,3}-?|\(0\d{2,3}\))?[1-9]\d{4,7}(-\d{1,8})?$)|(^\/$)/, message: '请输入正确的联系方式!' }
          ],
          psnName: [ { required: true, message: '请输入我方经办人!' } ],
          psnMobile: [
            { required: true, message: '请输入联系方式!' },
            { pattern: /(^1\d{10}$|^(0\d{2,3}-?|\(0\d{2,3}\))?[1-9]\d{4,7}(-\d{1,8})?$)|(^\/$)/, message: '请输入正确的联系方式!' }
          ],
          signFile: [
            { required: true, message: '请上传用印文件!' }
          ],
          isFixedTime: [
            { required: true, message: '请选择定点合同!' }
          ],
          expireTime: [
            { required: true, message: '请选择到期日期!' }
          ],

          taxRate: [
              { required: true, message: '请输入税率!', trigger: 'blur' },
              { required: true, pattern: /^(([0-9][0-9]*)|([0]\.\d{0,2}|[1-9][0-9]*\.\d{0,2}))$/, message: '请输入正确的税率!' }
          ],
          expensesTaxation: [
              { required: true, message: '请输入税费!', trigger: 'blur' },
              { required: true, pattern: /^(([0-9][0-9]*)|([0]\.\d{0,2}|[1-9][0-9]*\.\d{0,2}))$/, message: '请输入正确的金额!' }
          ],
          invoiceCategory: [
              { required: true, message: '请选择发票类型!', trigger: 'blur' }
          ],
          deliveryTime: [
              { required: true, message: '请输入货期!', trigger: 'blur' },
              { pattern: /^[0-9]*[1-9][0-9]*$/, message: '请输入正整数!' }
          ],
          modeTransportation: [
              { required: true, message: '请选择运输方式!', trigger: 'blur' }
          ],
          trafficExpense: [
              { required: true, message: '请选择运输费承担方!', trigger: 'blur' }
          ],
          projectId: [
              { required: true, message: '请选择关联项目!', trigger: 'change' }
          ],
          teamId: [
              { required: true, message: '请选择关联团队!', trigger: 'change' }
          ],
          demandCompanName: [
              { required: true, message: '请选择需方公司名称!', trigger: 'change' }
          ],
          demandCompanyAddress: [
              { required: true, message: '请输入需方公司地址!', trigger: 'blur' }
          ],
          demandEntrustedAgent: [
              { required: true, message: '请输入需方委托代理人!', trigger: 'blur' }
          ],
          demandPhoneNumber: [
              { required: true, message: '请输入需方手机号码!', trigger: 'blur' },
              { pattern: /^1[3456789]\d{9}$/, message: '请输入正确的手机号码!' }
          ],
          demandBankName: [
              { required: true, message: '请选择需方开户银行!', trigger: 'change' }
          ],
          demandBankAccountNo: [
              { required: true, message: '请输入需方银行账号!', trigger: 'blur' },
              // { pattern: /^[1-9]{1}\d{7,29}$/, message: '请输入正确的银行卡号!' }
          ],
          demandRegistrationNumber: [
              { required: true, message: '请输入需方纳税人识别号!', trigger: 'blur' }
          ],
          supplyCompanName: [
              { required: true, message: '请选择供应商名称名称!', trigger: 'change' }
          ],
          supplyCompanyAddress: [
              { required: true, message: '请输入供方公司地址!', trigger: 'blur' }
          ],
          contractOrgFile: [
              { required: false, message: '上传合同原件扫描件!', trigger: 'change' }
          ],
          supplyEntrustedAgent: [
              { required: true, message: '请输入供方委托代理人!', trigger: 'blur' }
          ],
          supplyPhoneNumber: [
              { required: true, message: '请输入供方手机号码!', trigger: 'blur' },
              { pattern: /^1[3456789]\d{9}$/, message: '请输入正确的手机号码!' }
          ],
          supplyBankName: [
              { required: true, message: '请输入供方开户银行!', trigger: 'blur' }
          ],
          supplyBankAccountNo: [
              { required: true, message: '请输入供方银行账号!', trigger: 'blur' },
              // { pattern: /^[1-9]{1}\d{7,29}$/, message: '请输入正确的银行卡号!' }
          ],
          supplyRegistrationNumber: [
              { required: true, message: '请输入供方纳税人识别号!', trigger: 'blur' }
          ],
          deliveryAddress: [
              { required: true, message: '请输入交货地址!', trigger: 'blur' }
          ],
          consignee: [
              { required: true, message: '请输入收货人!', trigger: 'blur' }
          ],
          phoneNumber: [
              { required: true, message: '请输入收货人电话!', trigger: 'blur' },
              { pattern: /^1[3456789]\d{9}$/, message: '请输入正确的电话号码!' }
          ],
          invoiceAddress: [
              { required: true, message: '请输入发票邮寄地址!', trigger: 'blur' }
          ],
          invoiceConsignee: [
              { required: true, message: '请输入发票收件人!', trigger: 'blur' }
          ],
          invoiceNumber: [
              { required: true, message: '请输入发票收货人电话!', trigger: 'blur' },
              { pattern: /^1[3456789]\d{9}$/, message: '请输入正确的电话号码!' }
          ],
          isProject: [
              { required: true, message: '请选择是否关联项目!', trigger: 'blur' }
          ],
          isEngineering: [
              { required: true, message: '请选择是否工程类!', trigger: 'blur' }
          ],
          contractName: [
            { required: true, message: '请输入合同名称!', trigger: 'blur' }
          ],
          isUseSeal: [
            { required: true, message: '请选择是否用印!' }
          ],
          sealType: [
            { required: true, message: '请选择印章类型!' }
          ],
          procurementType: [
            { required: true, message: '请选择采购类型!' }
          ],
          associationBillId: [
            { required: true, message: '请选择关联单据!' }
          ],
          useSealNumber: [
            { required: true, message: '请填写用印份数!', trigger: 'blur' },
            { pattern: /^[0-9]*[1-9][0-9]*$/, message: '请输入正整数!' }
          ],
        },
        url: {
          add: '/api/erp/purchase/contract/erpPurchaseContract/add',
          edit: '/api/erp/purchase/contract/erpPurchaseContract/edit',
          gainBillNo: '/api/erp/purchase/contract/erpPurchaseContract/gainBillNo',
          queryById: '/api/erp/purchase/contract/erpPurchaseContract/queryById',
          //获取定标结果确认单信息
          queryCalibrationById: '/api/erp/purchase/procurement/erpPurchaseCalibration/queryById',
          //获取采购申请单信息
          queryPurchaseApplyById: '/api/erp/purchase/procurement/erpPurchaseApplyForm/queryById',
          //获取招标采购单信息
          queryInvitationById: '/api/erp/purchase/procurement/erpPurchaseApplyInvitation/queryById'
        },
        teamIdBackups: null,
        userName: ''
      }
    },
    watch: {
      activeKey(key) {
        this.$forceUpdate()
      },

      // 监听税费
      'model.totalAmount': {
        handler (val) {
          this.$nextTick(() => {
            if (val && this.model.taxRate) {
              // 税费=合同额/（1+税率）* 税率
              var money = new Decimal(this.model.totalAmount).div(new Decimal(1).add(new Decimal(this.model.taxRate).div(new Decimal(100)))).mul(new Decimal(this.model.taxRate).div(new Decimal(100)))
              this.$set(this.model, 'expensesTaxation', money.toFixed(2))
            } else {
              this.$set(this.model, 'expensesTaxation', 0)
            }
          })
        },
        immediate: true,
        deep: true
      }
    },
    computed: {
      formDisabled() {
        if (this.formBpm === true) {
          if (this.formData.disabled === false) {
            return false
          }
          return true
        }
        return this.disabled
      },
      showFlowSubmitButton() {
        if (this.formBpm === true) {
          if (this.formData.disabled === false) {
            return true
          }
        }
        return false
      },
      isShowSeal () {
        if (this.model.isUseSeal && this.model.isUseSeal == 1) {
          return true
        } else {
          return false
        }
      },
    },
    created () {
       // 备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
      // 如果是流程中表单，则需要加载流程表单data
      this.showFlowData();
    },
    methods: {
      checkDisabled(key) {
        if (this.formBpm) {
          const keyStrategy = {
            fxmhtgly: ['contractOrgFile'],
          }
          const ignoreKeys = keyStrategy[this.formData.extendUrlParams?this.formData.extendUrlParams.node:''] || []
          if (ignoreKeys.includes(key)) {
            if (key == 'contractOrgFile') {
              this.validatorRules.contractOrgFile[0].required = true
            }
            return false
          }
            if (key == 'contractOrgFile') {
              this.validatorRules.contractOrgFile[0].required = false
            }
          return true
        }
        this.validatorRules.contractOrgFile[0].required = false
        return this.formDisabled
      },
      // 是否定点
      isFixedTimeInput (val) {
        this.$set(this.model, 'expireTime', null)
        this.$refs.form.clearValidate('expireTime');
      },
      // 是否工程类
      isEngineeringInput (val) {
        if(val == '1') {
          this.$set(this.model, 'projectId', null)
        }
      },
      ...mapGetters(['userInfo']),
      invoiceCategoryBlur (value) {
        this.$refs.form.clearValidate('taxRate');
        if(value == 0) {
          this.$set(this.model, 'taxRate', 0)
        } else {
          this.$set(this.model, 'taxRate', null)
        }
        this.$set(this.model, 'expensesTaxation', 0)
      },

      // 选择是否用印
        handleChangeSeal(val) {
        this.$set(this.model, 'signSealWay', null) // 置空电子签章
      },
      // 选择电子签章
      handleSignSealWay (val) {
        this.$set(this.model, 'isSignSeal', '0') // 对方是否电子签章默认为否
        this.$set(this.model, 'psnName', null)
        this.$set(this.model, 'psnMobile', null)
        this.$set(this.model, 'supplyPsnName', null)
        this.$set(this.model, 'supplyPsnMobile', null)
      },
      // 点击对方是否为电子签章
      isSignSealInput () {
        this.$set(this.model, 'supplyPsnName', null)
        this.$set(this.model, 'supplyPsnMobile', null)
      },
      // 税率输入框变化时
      inputTaxRateBlur (value) {
        let item = value.srcElement._value.toString().slice(0, 2)
        let data = value.srcElement._value.toString().replace(/\b(0+)/gi, '')
        if(this.model.invoiceCategory !== '0' && item !== "0.") {
          // 去除0
          var num = data
        }
        if(data == ".") {
          this.$set(this.model, 'taxRate', null)
        }
        if (num >= 0 && num < 100) {
          this.$set(this.model, 'taxRate', num)
        }
        if (num < 0) {
          this.$set(this.model, 'taxRate', 0)
        }
        if (num >= 100) {
          this.$set(this.model, 'taxRate', 100)
        }
        if(!!this.model.totalAmount){
          // 税费=合同额/（1+税率）* 税率
          var money = new Decimal(this.model.totalAmount).div(new Decimal(1).add(new Decimal(this.model.taxRate).div(new Decimal(100)))).mul(new Decimal(this.model.taxRate).div(new Decimal(100)))
          this.$set(this.model, 'expensesTaxation', money.toFixed(2))
        }
        this.$refs.form.clearValidate('expensesTaxation');
      },
      isProjectBlur(item) {
        this.$set(this.model, 'projectId', null)
      },

      getBillNo () {
        const that = this
        getAction(this.url.gainBillNo).then((res) => {
          if (res.success) {
            that.model.purchaseBill = res.result// 单据编号
            // that.model.bpmBizTitle = that.userName + '-' + that.model.purchaseBill // 标题
          }
        })
      },
      add () {
        this.edit(this.modelDefault);
        this.userName = this.userInfo().empName;// 当前登录人名称
        this.model.proposer = this.userInfo().empId; // 当前登录人
        this.model.proposerDeptId = this.userInfo().deptId; //当前登录人部门
        this.$set(this.model, 'deliveryTimeUnit', '3')
        this.model.createTime = moment().format('YYYY-MM-DD HH:mm:ss');
        this.getBillNo() // 获取单据编号
      },
      edit (record) {
        this.$refs["form"].clearValidate();
        this.model = Object.assign({}, record);
        if (this.formDisabled  && this.model.associationBillId){


          if (this.model.procurementType === '1'){
            //根据ID获取定标结果确认单单号 用于穿透
            getAction(this.url.queryCalibrationById,{id:this.model.associationBillId}).then(res=>{
              this.$set(this.model,'calibrationNo',res.result.purchaseBill);
            }).catch(e=>{
              console.log(e)
            })
          }else if (this.model.procurementType === '2'){
            //根据ID获取采购申请单单号 用于穿透
            getAction(this.url.queryPurchaseApplyById,{id:this.model.associationBillId}).then(res=>{
              this.$set(this.model,'purchaseNo',res.result.purchaseBill);
            }).catch(e=>{
              console.log(e)
            })
          }else if (this.model.procurementType === '3'){
            //根据ID获取招标采购单信息单号 用于穿透
            getAction(this.url.queryInvitationById,{id:this.model.associationBillId}).then(res=>{
              this.$set(this.model,'invitationNo',res.result.purchaseBill);
            }).catch(e=>{
              console.log(e)
            })
          }

        }

        if (this.model.id) {
          this.$refs.contractPayment.loadData(1, this.model.id)
          this.$refs.contractSupplies.loadData(1, this.model.id)
        } else {
          this.$refs.contractPayment.dataSource = []
          this.$refs.contractSupplies.dataSource = []
        }
        this.visible = true;
      },
      bankBack(item) {
        var dataBack = item[0]
        this.$set(this.model, 'demandBankName', dataBack.openingBank) // 公司地址
      },
      handleChangeProvisionType(val) {
        if (val == '1') {
          this.$set(this.validatorRules, 'associationBillId', [{ required: true, message: '请选择关联单据!' }]);
          //清除采购申请单数据及校验
          this.$set(this.model, 'associationBillId', null);
        } else if (val == '2') {
          this.$set(this.validatorRules, 'associationBillId', [{ required: true, message: '请选择关联单据!' }]);
          this.$set(this.model, 'associationBillId', null);
        }else if(val == '3'){
          this.$set(this.validatorRules, 'associationBillId', [{ required: true, message: '请选择关联单据!' }]);
          //清除采购申请单数据及校验
          this.$set(this.model, 'associationBillId', null);
        }else {
          //清除关联单据ID数据及校验
          this.$set(this.model, 'associationBillId', null);
          this.$delete(this.validatorRules, 'associationBillId');
        }
      },
      teamBack(item) {
        if(!!this.model.teamId && item.length > 0) {
          if(this.teamIdBackups !== item[0].id && !!this.model.projectId) {
            this.$set(this.model, 'projectId', null)
          }
          this.teamIdBackups = item[0].id
        }
      },

      // 需方选择往来单位
      demandCompanNameInput (item) {
        this.$refs.form.clearValidate('demandCompanyAddress');
        this.$refs.form.clearValidate('demandRegistrationNumber');
        this.$refs.form.clearValidate('demandBankName');
        this.$refs.form.clearValidate('demandBankAccountNo');
        if (item.length > 0) {
          var dataBack = item[0]
          this.$set(this.model, 'demandCompanyAddress', dataBack.enterpriseAddress) // 公司地址
          this.$set(this.model, 'demandRegistrationNumber', dataBack.enterpriseCreditCode) // 纳税人识别号
          this.$set(this.model, 'demandBankName', dataBack.bankName) // 开户行
          this.$set(this.model, 'demandBankAccountNo', dataBack.bankAccountNo) // 银行账户
        } else {
          this.$set(this.model, 'demandCompanyAddress', null) // 公司地址
          this.$set(this.model, 'demandRegistrationNumber', null) // 纳税人识别号
          this.$set(this.model, 'demandBankName', null) // 开户行
          this.$set(this.model, 'demandBankAccountNo', null) // 银行账户
        }
      },

      // 供方选择往来单位
      supplyCompanBack (item) {
        var dataBack = item[0]

        this.$refs.form.clearValidate('supplyCompanyAddress');
        this.$refs.form.clearValidate('supplyBankName');
        this.$refs.form.clearValidate('supplyBankAccountNo');
        this.$refs.form.clearValidate('supplyRegistrationNumber');
        this.$set(this.model, 'supplyCompanyAddress', dataBack.enterpriseAddress) // 公司地址
        this.$set(this.model, 'supplyBankName', dataBack.bankName) // 开户银行
        this.$set(this.model, 'supplyBankAccountNo', dataBack.bankAccountNo) // 银行账号
        this.$set(this.model, 'supplyRegistrationNumber', dataBack.enterpriseCreditCode) // 纳税人识别号
      },

      onTotalMoney (e) {
        this.$set(this.model, 'totalAmount', e)
      },

      // 渲染流程表单数据
      showFlowData() {
        if (this.formBpm === true) {
          let params = { id: this.formData.dataId };
          getAction(this.url.queryById, params).then((res) => {
            if (res.success) {
              this.edit(res.result);
            }
          });
        }
      },

      goPurchaseCalibrationDetail(record){
        this.$refs.purchaseCalibrationBillPenetrate.initData(record.associationBillId);
        this.$refs.purchaseCalibrationBillPenetrate.visible = true;
      },
      goPurchaseApplyDetail(record){
        this.$refs.purchaseApplyFormPenetrate.initData(record.associationBillId);
        this.$refs.purchaseApplyFormPenetrate.visible = true;
      },
      goInvitationDetail(record){
        this.$refs.purchaseInvitationFormPenetrate.initData(record.associationBillId);
        this.$refs.purchaseInvitationFormPenetrate.visible = true;
      },

      submitForm(type) {
        const that = this;
        if (type == 'draft') {
          // 代表保存草稿不做校验
          this.submit(type)
        } else if (type == 'submit') {
          // 触发表单验证

          let contractPayment = this.$refs.contractPayment.submitForm() // 付款信息
          let contractSupplies = this.$refs.contractSupplies.submitForm() // 物料信息
          let calculateRatioPayment = this.$refs.contractPayment.calculateRatioPayment()
          if (!contractPayment.length > 0) {
            this.$message.warning('请添加付款信息！');
            this.$emit('unButtonDisable');
            return
          }

          if (calculateRatioPayment < 100) {
            this.$message.warning('付款信息中付款比例之和没有达到100%！');
            this.$emit('unButtonDisable');
            return
          }

          if (!contractSupplies.length > 0) {
            this.$message.warning('请添加物料信息！');
            this.$emit('unButtonDisable');
            return
          }

          for (var i = 0; i < contractSupplies.length; i++) {
            if (!contractSupplies[i].unitPrice) {
              this.$message.warning('请输入物料信息单价！');
              this.$emit('unButtonDisable');
              return false
            }
          }

          if (!this.model.deliveryTimeUnit) {
            this.$message.warning('请选择货期单位！');
              this.$emit('unButtonDisable');
              return false
          }
          this.$refs.form.validate(valid => {
            if (valid) {
              that.submit(type)
            } else {
              that.$emit('unButtonDisable')
            }
          })
        } else {
          console.log('传参数，保存：draft，提交：submit')
        }
      },
      submit (type) {
        const that = this;
        that.confirmLoading = true;
        let httpurl = '';
        let method = '';
        if (!this.model.id) {
          httpurl += this.url.add;
          method = 'post';
        } else {
          httpurl += this.url.edit;
          method = 'put';
        }
        let contractPayment = this.$refs.contractPayment.submitForm() || [] // 付款信息
        let contractSupplies = this.$refs.contractSupplies.submitForm() || [] // 物料信息
        this.model.purchaseContractPayments = contractPayment
        this.model.purchaseContractSupplies = contractSupplies
        this.model.bpmBizTitle = this.model.contractName || ''
        httpAction(httpurl, this.model, method).then((res) => {
          if (res.success) {
            that.$message.success(res.message);
            if (method == 'post') {
              that.model.id = res.result;
            }
            that.$emit('ok', type, that.model);
          } else {
            that.$message.warning(res.message);
            that.$emit('unButtonDisable');
          }
        }).catch((error) => {
          that.$emit('unButtonDisable', error);
        }).finally(() => {
          that.confirmLoading = false;
        })
      },

      // 点击打印
      onPrint () {
        let print = new Print({
          el: '#contractContent',
          popTitle: '非项目付款合同详情 · 禾美环保',
          endCallback() {

          }
        })
      }
    }
  }
</script>
<style>
  @import "../../../../../utils/print.css";
  .print_style{
  position: absolute;
  top: 0;
  z-index: -1111;
}
</style>